import vouterConfig from "@/router/vouter.config";

const routerTool = {
  isHide: (i) => {
    return Object.keys(i).indexOf("redirect") === -1
      && !(i.meta && i.meta.isHideMenu)
  },
  getMenuTree: () => {
    const HomeRouter = vouterConfig.filter(i => {
      return i.path === "/Home"
    })[0]
    const validRouter = HomeRouter.children.filter(i => routerTool.isHide(i))
    const handleRouter = validRouter.map((item, index) => {
      return {
        id: `${index + 1}`,
        title: item.meta.title,
        icon: item.meta.icon,
        children: item.children.filter(i => routerTool.isHide(i)).map((child, childIndex) => {
          return {
            id: `${index + 1}-${childIndex + 1}`,
            title: child.meta.title,
            path: `/Home/${item.path}/${child.path}`
          }
        })
      }
    })
    return handleRouter
  },


  getRoleAuthTree: () => {
    const HomeRouter = vouterConfig.filter(i => {
      return i.path === "/Home"
    })[0]
    const validRouter = HomeRouter.children.filter(i => routerTool.isHide(i))
    const handleRouter = validRouter.map((item, index) => {
      return {
        key: `${index + 1}`,
        title: item.meta.title,
        children: item.children.filter(i => routerTool.isHide(i)).map((child, childIndex) => {
          return {
            key: `${index + 1}-${childIndex + 1}`,
            title: child.meta.title,
          }
        })
      }
    })
    return handleRouter
  }
}

export default routerTool